package awake.stu.dbhb;

import javax.swing.*;
import javax.swing.table.TableCellEditor;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.Date;
import java.util.EventObject;

import com.toedter.calendar.JDateChooser;

/**
 * Created by IntelliJ IDEA.
 * User: Awake
 * Date: 27.02.12
 * Time: 12:41
 * To change this template use File | Settings | File Templates.
 */
public class DateTableCellEditor extends AbstractCellEditor implements TableCellEditor {
    JDateChooser dateChooser = new JDateChooser();
    public Component getTableCellEditorComponent(JTable table, Object value,
                                                 boolean isSelected, int row, int column) {
        dateChooser.setDate((Date) value);
        dateChooser.setDateFormatString("dd.mm.yyyy");
        return dateChooser;
    }
    // Enables the editor only for double-clicks.
    public boolean isCellEditable(EventObject evt) {
        if (evt instanceof MouseEvent) {
            return ((MouseEvent) evt).getClickCount() >= 2;
        }
        return true;
    }
    // Returns the current value.
    public Object getCellEditorValue() {
        return dateChooser.getDate();
    }
}